package com.mba.webservice;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

import com.mba.bean.MBAParameters;
import com.mba.bean.Message;



public class MessageAPI extends MbaAPI {
	
	private static final String SERVER_URL_PRIX = API_SERVER + "/statuses";
	
	
	/**
	 * 获取推送给当前用户的20条最新消息。
	 * 
	 * @version 0.1
	 */
	public List<Message> getHomeTimeline(String id) throws Exception {

		MBAParameters params = new MBAParameters();
		params.add("uid", id);

		/*String strMsgList = request(SERVER_URL_PRIX + "/home_timeline"
				+ ".json", params, HTTPMETHOD_GET);*/
		
		String strMsgList = request("http://48k.cc/json.txt", params, HTTPMETHOD_GET);
		

		JSONObject json = toJSONObject(strMsgList);

		JSONArray list = json.getJSONArray("messages");
		int size = list.length();
		
		
		List<Message> msgList = new ArrayList<Message>(size);

		for (int i = 0; i < size; i++) {
			Log.w("list:"+i,list.getJSONObject(i).toString());
			msgList.add(new Message(list.getJSONObject(i)));
		}

		return msgList;
	}
	

}